// /////////////////////////////////////////////////////////////////////////////
//
// Name:            Serializable.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Declaration of the Serializable class.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

// Makes sure that SerializedAttributes can inherit from Serializable.
#ifndef __SERIALIZABLE_H_UPPER_TIER__

#include "SerializedAttributes.h"

#ifndef __SERIALIZABLE_H__
#define __SERIALIZABLE_H__
#define __SERIALIZABLE_H_UPPER_TIER__

// Include files
#include "../dependencies.h"
#include "ReferenceCounted.h"


// Forward declarations
class SerializedAttributes;
class SerializedAttribute;


// Serializable class
//! The Serializable class provides a base for classes that need serialization.
//! By deriving from this class, the derived class gains all required methods
//! for serialization.
class Serializable : public ReferenceCounted
{
public:

    // Initialisation and deinitialisation
    //! Constructor
    Serializable();
    //! Deconstructor
    virtual ~Serializable();

    // Public methods
    //! Serializes this object.
    //! @param attributes
    virtual bool onSerialization(SerializedAttributes *attributes) = 0;
    //! Deserializes this object.
    //! @param attributes
    virtual bool onDeserialization(SerializedAttributes *attributes) = 0;

    //! Loads this object from a XML file.
    //! @param fileName      Filename of the file where the data is retrieved from.
    bool loadXML(const std::string &fileName);
    //! Loads this objects from a XML file through the given IXMLReader object.
    //! @param file          Pointer to the IXMLWriter object that will be used.
    bool loadXML(IXMLReader *file);
    //! Saves this object to a XML file.
    //! @param fileName      Filename of the file where the data is saved to.
    bool saveXML(const std::string &fileName);
    //! Saves this object to a XML file through the given IXMLWriter object.
    //! @param file          Pointer to the IXMLWriter object that will be used.
    bool saveXML(IXMLWriter *file);

private:

    // Private methods
    SerializedAttribute* parseAttribute(const std::string &name, const std::string &type,
                                        const std::string &value);
};

#endif // __SERIALIZABLE_H__

#endif // __SERIALIZABLE_H_UPPER_TIER__
